<?php
/**
 * Created by PhpStorm.
 * User: ASUS
 * Date: 2019/10/17
 * Time: 9:20
 */

namespace app\index\controller;


use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Mini extends Controller
{
    public function api(){
        $request=Request::instance();
        $name=$request->param('name');
        $sid=$request->param('sid');
        $sk=$request->param('sk');
        session_id($sid);
        session_start();
        echo Session::get($sk);
        exit;
        if($name==123){
            echo "对";
        }else{
            echo "错";
        }
        exit();
    }
    public function listw(){
        $request=Request::instance();
        $p=$request->param('p');
        $arr=Db::table('words')->page($p,10)->select();
        echo json_encode($arr);
    }
    public function upload(){
        $request=Request::instance();
        $info=$request->file("up")->move(ROOT_PATH.'public'.DS.'uploads');
        echo $info->getSaveName();
        exit;
    }
    public function login(){
        $request=Request::instance();
        $code=$request->param('code');
        $appid="wx1812ad1de352a28c";
        $secret="f6310620dd48f4fad69ec63a73d4ebc2";
        $url="https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
        $rt=https_request($url);
        $arr=json_decode($rt,true);
        Session::set($arr['session_key'],$arr['openid']);
        echo json_encode(['sk'=>$arr['session_key'],'sid'=>session_id()]);
        exit;
    }
}